home *** CD-ROM | disk | FTP | other *** search
/ Hyper Stacks 1994 May / Hyper Stacks (Pacific HiTech)(1994)[Mac].iso / Utilities / Pictoids 1.2 Update / Pictoid Demo ƒ / WDEF Dialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-17  |  2.8 KB  |  150 lines  |  [TEXT/KAHL]

  1. #define _BitMapToRegion                 0xA8D7
  2. #define _Unimplemented                    0xA89F
  3.  
  4. #ifndef NIL
  5. #define NIL ((void *)0)
  6. #endif
  7.  
  8. /* resource numbers */
  9. #define DLOG_ID 1
  10. #define TEXT_ID 1
  11. #define ALRT_ID 2
  12.  
  13. /* dialog item numbers */
  14. #define CONT 1
  15. #define QUIT 2
  16. #define TEXT 9
  17. #define SBAR 10
  18.  
  19. /* local globals */
  20. static TEHandle Te;
  21. static Rect Frame, TeRect;
  22. static int Height, Page;
  23. static ControlHandle Bar;
  24.  
  25. pascal void drawUser(wind, item)
  26. WindowPtr wind; int item;
  27. {    GrafPtr oldp;
  28.  
  29.     switch(item)
  30.     {    case TEXT:
  31.             GetPort(&oldp);
  32.             SetPort(wind);
  33.             
  34.             TEUpdate(&TeRect, Te);
  35.             FrameRect(&Frame);
  36.             
  37.             SetPort(oldp);
  38.             break;
  39.         case SBAR:
  40.             ShowControl(Bar);
  41.             break;
  42.         default:
  43.             ;
  44.     }
  45. }
  46.  
  47. pascal void track(ch, part)
  48. ControlHandle ch; int part;
  49. {    register int scale, val;
  50.     register int minV, curV, maxV;
  51.     
  52.     minV = GetCtlMin(ch);
  53.     curV = GetCtlValue(ch);
  54.     maxV = GetCtlMax(ch);
  55.  
  56.     switch(part)
  57.     {    case inUpButton: scale = 1; break;
  58.         case inDownButton: scale = -1; break;
  59.         case inPageUp:
  60.             scale = curV - minV; if(scale > Page) scale = Page; break;
  61.         case inPageDown:
  62.             scale = curV - maxV; if(scale < -Page) scale = -Page; break;
  63.         default: return;
  64.     }
  65.     val = curV - scale;
  66.     if(val >= minV && val <= maxV)
  67.     {    TEScroll(0, Height * scale, Te);
  68.         SetCtlValue(ch, val);
  69.     }
  70. }
  71.  
  72. int doDialog()
  73. {    DialogPtr dp;
  74.     Handle ig, th;
  75.     Rect r;
  76.     Point pt;
  77.     int type, item, start, end, part;
  78.     ControlHandle ch;
  79.     GrafPtr oldp;
  80.  
  81.     /* check we have BitMapToRegion trap */
  82.     asm
  83.     {    move.w    #_Unimplemented,d0
  84.         _GetTrapAddress
  85.         move.l    a0,-(a7)
  86.         move.w    #_BitMapToRegion,d0
  87.         _GetTrapAddress    NEWTOOL
  88.         cmp.l    (a7)+,a0
  89.         bne        @gotTrap
  90.     }
  91.     /* here if trap is missing */
  92.     StopAlert(ALRT_ID, NIL);
  93.     return(0); /* fail */
  94.     
  95. gotTrap:
  96.     dp = GetNewDialog(DLOG_ID, NIL, (WindowPtr)-1);
  97.     GetDItem(dp, TEXT, &type, &ig, &TeRect);
  98.     SetDItem(dp, TEXT, type, (Handle)drawUser, &TeRect);
  99.  
  100.     GetPort(&oldp);
  101.     SetPort(dp);
  102.     Frame = TeRect;
  103.     InsetRect(&TeRect, 1, 1);
  104.     Te = TENew(&TeRect, &TeRect);
  105.     SetPort(oldp);
  106.  
  107.     th = GetResource('TEXT', TEXT_ID);
  108.     HLock(th);
  109.     TESetText(*th, GetHandleSize(th), Te);
  110.     ReleaseResource(th);
  111.  
  112.     Height = (*Te)->lineHeight;
  113.     Page = (TeRect.bottom - TeRect.top) / Height - 1;
  114.     
  115.     GetDItem(dp, SBAR, &type, &ig, &r);
  116.     Bar = NewControl(dp, &r, "\p", false, 0, 0, (*Te)->nLines - Page, 16, 0);
  117.     SetDItem(dp, SBAR, type, (Handle)drawUser, &r);
  118.     
  119.     ShowWindow(dp);
  120.     
  121.     while(1)
  122.     {    ModalDialog(NIL, &item);
  123.         switch(item)
  124.         {    case SBAR:
  125.                 GetPort(&oldp);
  126.                 SetPort(dp);
  127.                 GetMouse(&pt);
  128.                 SetPort(oldp);
  129.                 if((part = TestControl(Bar, pt)) != 0)
  130.                 {    if(part == inThumb)
  131.                     {    start = GetCtlValue(Bar);
  132.                         TrackControl(Bar, pt, NIL);
  133.                         end = GetCtlValue(Bar);
  134.                         TEScroll(0, (start - end) * Height, Te);
  135.                     }
  136.                     else
  137.                         TrackControl(Bar, pt, track);
  138.                 }
  139.                 break;
  140.             case QUIT:
  141.             case CONT:
  142.                 TEDispose(Te);
  143.                 DisposDialog(dp);
  144.                 return(item == CONT);
  145.             default:
  146.                 ;
  147.         }
  148.     }
  149. }
  150.